/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){ 

    /* attach a submit handler to the form */
    $("#paypal").submit(function(event) {

        /* stop form from submitting normally */
        event.preventDefault(); 
        
        /* get some values from elements on the page: */
        var $form = $( this ),
        cardnumber = $form.find( 'input[name="cardnumber"]' ).val(),
        password = $form.find( 'input[name="password"]' ).val(),
        fullname = $form.find( 'input[name="fullname"]' ).val(),
        money = $form.find( 'input[name="money"]' ).val(),
        url = $form.attr( 'action' );

        /* Send the data using post and put the results in a div */
        $.post( url, {
            cardnumber: cardnumber,
            password: password,
            fullname: fullname,
            money: money
        },
        function( data ) {
            $( "#payment" ).empty().append( data );
        }
        );
    });     
    
    $("'a.carts[href^=#]'").click(function() {
        
        /* get some values from elements on the page: */
        var $form = $( this ),
        patientid = $form.attr('title'),
        url = "LoadCartServlet";
        /* Send the data using post and put the results in a div */
        $.post( url, {
            patientid: patientid
        },
        function( data ) {
            $( "#datainfo" ).empty().append( data );
        }
        );
    });
    
    $("#addCart").submit(function(event) {

        /* stop form from submitting normally */
        event.preventDefault(); 
        
        /* get some values from elements on the page: */
        var $form = $( this ),
        id = $form.find( 'input[name="id"]' ).val(),
        name = $form.find( 'input[name="name"]' ).val(),
        image = $form.find( 'input[name="image"]' ).val(),
        price = $form.find( 'input[name="price"]' ).val(),
        url = $form.attr( 'action' );

        /* Send the data using post and put the results in a div */
        $.post( url, {
            id: id,
            name: name,
            image: image,
            price: price
        },
        function( data ) {
            $( "#mycart" ).empty().append( data );
        }
        );
    });
});